import React from "react";
import { NavLink, Routes, Route } from "react-router-dom";
import "./09-style.css";

const Home = () => {
  return <div>这是首页</div>;
};

const About = () => {
  return <div>这是关于页</div>;
};

const App = () => {
  return (
    <>
      <h2>react-router-v6-高亮</h2>
      <ul>
        <li>
          {/* 如果要改高亮的类名，只能手动改 */}
          {/* NavLink的className可以接收一个函数 */}
          <NavLink
            to="/home"
            className={({ isActive }) => {
              // if (isActive) {
              //   return "select"
              // } else {
              //   return ""
              // }
              return isActive ? "select" : "";
            }}
          >
            首页
          </NavLink>
        </li>
        <li>
          <NavLink to="/about">关于页</NavLink>
        </li>
      </ul>

      <hr />

      <Routes>
        <Route path="/home" element={<Home />}></Route>
        <Route path="/about" element={<About />}></Route>
        {/* 404路由要写到最后 */}
        <Route path="*" element={<div>404 not found...</div>}></Route>
      </Routes>
    </>
  );
};

export default App;
